package com.test.resumeanalysis.ui.talent

import android.view.LayoutInflater
import android.view.ViewGroup
import com.test.resumeanalysis.R
import com.test.resumeanalysis.common.CommonRvAdapter
import com.test.resumeanalysis.common.CommonRvHolder
import com.test.resumeanalysis.data.model.resume.ResumeParse
import com.test.resumeanalysis.databinding.RvPostInfoBinding

class TalentAdapter: CommonRvAdapter<ResumeParse, RvPostInfoBinding>() {
    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): CommonRvHolder<RvPostInfoBinding> {
        val inflate = RvPostInfoBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return CommonRvHolder(inflate)
    }

    override fun onBindViewHolder(
        holder: CommonRvHolder<RvPostInfoBinding>,
        position: Int,
        binding: RvPostInfoBinding,
        bean: ResumeParse
    ) {

        if (bean.parsing_result.basic_info.gender=="男"){
            holder.binding.imageView.setImageResource(R.drawable.boy)
        }else{
            holder.binding.imageView.setImageResource(R.drawable.girl)
        }

        holder.itemView.setOnClickListener {
            mOnItemClickListener?.onItemClick(position)
        }

        holder.binding.postInfoName.text  = bean.parsing_result.basic_info.name
        holder.binding.postInfoSchool.text = bean.parsing_result.basic_info.school_name
        holder.binding.postInfoWorkTime.text  = bean.parsing_result.basic_info.degree

        if (bean.parsing_result.work_experience.isNotEmpty()) {
            holder.binding.postInfoWorkEp.text  = bean.parsing_result.work_experience[0].description
        }
    }


    //创建OnItemClickListener接口
    interface OnItemClickListener {
        fun onItemClick(position: Int)
    }

    //声明一个mItemClickListener接口
    private var mOnItemClickListener: OnItemClickListener? = null

    //添加setOnItemClickListener方法
    fun setOnItemClickListener(listener: OnItemClickListener?) {
        mOnItemClickListener = listener
    }
}